﻿using System;
using System.Data;
using System.Data.SQLite;
using System.Threading;

namespace Goooodbye.Presentation.ConsoleApp
{
    public class DbConnectionFactory
    {
        private static readonly string connectionString = $"Data Source={AppDomain.CurrentDomain.BaseDirectory}app_data.db;Version=3;";

        private DbConnectionFactory() { }

        private static readonly ThreadLocal<IDbConnection> connectionThreadLocal = new ThreadLocal<IDbConnection>(() =>
        {
            return CreateConnection();
        });

        public static IDbConnection GetConnection()
        {
            return connectionThreadLocal.Value;
        }

        private static IDbConnection CreateConnection()
        {
            return new SQLiteConnection(connectionString);
        }

    }

}
